home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 April
/
EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso
/
EARCD
/
comm
/
bbs
/
Hydra11s.lha
/
HBBS
/
Source
/
Doors_System
/
Transfer
/
Main.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-31
|
10KB
|
371 lines
/*
Transfer
========
the interface between a program that wants a file transfered between both computers
and the protocol drivers
E.G. the UPLOAD door calls TRANSFR which then calls the correct protocol driver
depending on what protocol the user has selected
N_ND->ActiveDoor->SystemOptions
===============================
No options used at this time
Door Options (Command Line)
===========================
UPLOAD|DOWNLOAD|BOTH
ProtocolNumber
WAREZ|NONWAREZ
[CHECKFILES]
[NOLOGOFF]
if the "checkfiles" keyword is present after parameter 2 we have to tell the
protocol door to call the "CHECK_FILES" door after each file has been uploaded
so that it can do background filechecking.
*C* Implement!!!
if NONWAREZ is specified then uploaded files get put in the playpen's/NonWarez dir
otherwise they go straight into the playpen.
if NOLOGOFF is specified then you won't get the option to [G]oodbye...
Example
=======
TRANSFER UPLOAD 2 CHECKFILES
Notes
=====
you MUST check that the protocol selected can cope with the type of transfer
Check UPLOAD|DOWNLOAD|BOTH against the following
BBSGlobal->ProtocolList->ProtocolNode->protocoltype
BBSGlobal->ProtocolList->ProtocolNode->allow_ul
BBSGlobal->ProtocolList->ProtocolNode->allow_dl
Also check the following
BBSGlobal->ProtocolList->ProtocolNode->allow_batch
if allow_batch is off and the transfer type is DOWNLOAD you must call the protocol
door for each file that the user wants download...
Hehe and now to confuse you.. to the USER pressing U starts the UPLOAD door,
which means the USER is going to UPLOAD some files therefore we mus start the
protocol DOWNLOAD door, rahter than an UPLOAD protocol :-) hehe and vise versa!
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif
#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>
#include <HBBS/hbbscommon_pragmas.h>
#include <HBBS/Hbbsnode_protos.h>
#include <HBBS/Hbbsnode_pragmas.h>
#include <HBBS/release.h>
char *versionstr="$VER: Transfer "RELEASE_STR;
struct Library *HBBSCommonBase=NULL;
struct Library *HBBSNodeBase=NULL;
struct BBSGlobalData *BBSGlobal=NULL;
struct NodeData *N_ND=NULL;
int N_NodeNum=-1;
char outstr[1024]; // temp string for displaying text..
#define T_NONE 0
#define T_UPLOAD 1
#define T_DOWNLOAD 2
#define T_BOTH 3
#define T_WAREZ 1
#define T_NONWAREZ 2
short transfertype=T_NONE;
short filetype=T_NONE;
struct ProtocolNode *PNode=NULL;
V_BIGNUM PNum;
static VOID cleanup(ULONG num)
{
if (HBBSNodeBase)
{
HBBS_CleanUpDoor();
CloseLibrary (HBBSNodeBase);
}
if (HBBSCommonBase)
{
HBBS_CleanUpCommon();
CloseLibrary (HBBSCommonBase);
}
if (num) printf("Door Error = %d\n",num);
exit(0);
}
static VOID init(char *name)
{
if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
{
cleanup(1);
}
if (!(HBBS_InitCommon()))
{
cleanup(2);
}
if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
{
cleanup(3);
}
if (!(HBBS_InitDoor(N_NodeNum,name)))
{
cleanup(4);
}
SetProgramName(name);
}
void DoorMain(int argc,char *argv[])
{
char options[4096]; // *C* v.big string!
struct TaggedFile *Tag;
char inputstr[10];
V_BIGNUM doorret,loop;
BOOL StillOK,allowgoodbye=TRUE;
if (argc<4)
{
DOOR_WriteText("Invalid Parameters, Check your config!\r\n");
}
else
{
for (loop=3;loop<argc;loop++)
{
if (stricmp(argv[loop],"NOGOODBYE")==0) allowgoodbye=FALSE;
}
if (stricmp(argv[2],"UPLOAD")==0) transfertype=T_UPLOAD;
if (stricmp(argv[2],"DOWNLOAD")==0) transfertype=T_DOWNLOAD;
if (stricmp(argv[2],"BOTH")==0) transfertype=T_BOTH;
if (transfertype!=T_NONE)
{
PNum=atoi(argv[3]);
if (PNum>=0 && PNum<BBSGlobal->Protocols)
{
PNode=(struct ProtocolNode *)GetNode(BBSGlobal->ProtocolList,PNum);
if (
(
(transfertype==T_UPLOAD) &&
(PNode->allow_ul)
)
||
(
(transfertype==T_DOWNLOAD) &&
(PNode->allow_dl)
)
||
(
(transfertype==T_BOTH) &&
(PNode->allow_dl) &&
(PNode->allow_ul) &&
(PNode->protocoltype == PTYPE_BIDIRECTIONAL)
)
)
{
// Protocol Checks out, so let's gooooo
if (stricmp("NONWAREZ",argv[4])==0) filetype=T_NONWAREZ;
if (stricmp("WAREZ",argv[4])==0) filetype=T_WAREZ;
if (filetype!=T_NONE)
{
strcpy(N_ND->CharsAllowed,"SsAa ");
strcpy(outstr,"[S]tart Transfer, ");
if (allowgoodbye)
{
strcat(outstr,"[G]oodbye after transfer, ");
strcat(N_ND->CharsAllowed,"Gg");
}
strcat(outstr,"[A]bort >");
DOOR_MenuPrompt(outstr,'S');
DOOR_GetLine(GL_USECHARS|GL_IMMEDIATE,'\0',1,0,NULL);
if (N_ND->OnlineStatus==OS_ONLINE)
{
strNcpy(inputstr,N_ND->CurrentLine,2);
switch(toupper(inputstr[0]))
{
case 'A':
DOOR_WriteText("Aborted!\r\n");
break;
case 'G':
DOOR_WriteText("Goodbye after xfer!\r\n");
break;
default:
DOOR_WriteText("Started!\r\n");
break;
}
switch(toupper(inputstr[0]))
{
case '\0':
case ' ':
case 'S':
case 'G':
if (transfertype==T_UPLOAD)
{
if (stricmp(PNode->modulename,"CLIProtocol")==0)
{
sprintf(options,"%s D=%s %s",PNode->moduleopts,N_ND->NodeSettings.NodePlayPen,filetype==T_NONWAREZ ? "NONWAREZ" : "");
DOOR_SystemDoor(PNode->modulename,options);
}
else
if (stricmp(PNode->modulename,"XPR")==0)
{
sprintf(options,"%s S D=%s",PNode->moduleopts,N_ND->NodeSettings.NodePlayPen);
DOOR_SystemDoor(PNode->modulename,options);
}
}
if (transfertype==T_DOWNLOAD)
{
if (stricmp(PNode->modulename,"CLIProtocol")==0)
{
DOOR_WriteText("This download method is only temporary!\r\n");
StillOK=TRUE;
while ((Tag = (struct TaggedFile *)N_ND->TaggedFileList->lh_Head) &&
(Tag ->node.ln_Succ) &&
(StillOK) &&
(N_ND->OnlineStatus==OS_ONLINE) &&
(!CarrierLost()))
{
sprintf(options,"%s U=%s %s",PNode->moduleopts,Tag->node.ln_Name,filetype==T_NONWAREZ ? "NONWAREZ" : "");
DOOR_SystemDoor(PNode->modulename,options);
if (strcmp(N_ND->DoorReturn,"0")==0 && N_ND->OnlineStatus==OS_ONLINE)
{
// deduct creds if transfer OK..
N_ND->User.CallData.DownloadFiles++;
N_ND->User.NormalData.DownloadFiles++;
N_ND->User.CallData.ActualDownloadFiles++;
N_ND->User.NormalData.ActualDownloadFiles++;
N_ND->User.CallData.DownloadBytes+=Tag->FileSize;
N_ND->User.NormalData.DownloadBytes+=Tag->FileSize;
N_ND->User.CallData.ActualDownloadBytes+=Tag->FileSize;
N_ND->User.NormalData.ActualDownloadBytes+=Tag->FileSize;
// and remove the taged file
FreeStr(Tag->node.ln_Name);
Remove((struct Node*)Tag);
FreeVec(Tag);
N_ND->TaggedFiles--;
}
else
{
StillOK=FALSE;
}
}
}
else
{
if (stricmp(PNode->modulename,"XPR")==0)
{
sprintf(options,"%s TAGS C",PNode->moduleopts);
DOOR_SystemDoor(PNode->modulename,options);
}
}
}
break;
}
if (inputstr[0]=='G')
{
DOOR_MenuPrompt("Press [Return] to cancel auto-logout, or [L]ogout Now >",' ');
doorret=DOOR_GetLine(GL_EDIT|GL_DISPLAY,'\0',1,5,NULL);
DOOR_WriteText("\r\n");
if (doorret==IN_TIMEOUT || toupper(N_ND->CurrentLine[0])=='L')
{
DOOR_UserDoor("G","NOPROMPT");
}
}
}
}
}
else
{
DOOR_WriteText("You have selected a type of transfer that this protocol\r\n"
"either does not support or has been disabled by the sysop!\r\n");
}
}
}
else DOOR_WriteText("Invalid Protocol!\r\n");
}
DOOR_Return("NOBATCH");
}
int main(int argc,char *argv[])
{
if (sscanf(argv[1],"%d",&N_NodeNum)==0)
{
printf("Invalid/No Paramaters for door!\n");
exit (20);
}
init("Transfer");
if (BBSGlobal=HBBS_GimmeBBS())
{
if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
{
DoorMain(argc,argv);
}
}
cleanup(0);
}